package com.googlecode.napp.server;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class ticket {
    private boolean Query(String Query)
    {
    	if(Db.Query(Query))
    		System.out.println("Query failed");
    	return true;
    }
    
    public void New(int user, String loc, String Problem, int Image, int onCall)
    {
    	Query("INSERT INTO rnd.ticket (username, loc, problem, oncall, image, date_start, date_end, status) VALUES (" +
    			user + ",\"" + loc + "\",\"" + Problem + "\"," + onCall + "," + Image + ",\"" + date() + "\"," + "0,0)");
    }
    
   public void changeUser(int t, int id)
   {
	   Query("INSERT INTO rnd.ticket (username) VALUES (" + id + ") WHERE tickitid = "+ t );
   }
   public void changeLoc(int ticketid, String loc)
   {
	   Query("INSERT INTO rnd.ticket (loc) VALUES (" + loc + ") WHERE tickitid = "+ ticketid );
   }
   public void changeProblem(int ticketid, String Problem)
   {
	   Query("INSERT INTO rnd.ticket (problem) VALUES (" + Problem + ") WHERE tickitid = "+ ticketid );
   }
   public void changeImage(int ticketid, int s)
   {
	   Query("INSERT INTO rnd.ticket (image) VALUES (" + s + ") WHERE tickitid = "+ ticketid );
   }
   public void changeOncall(int ticketid, int s)
   {
	   Query("INSERT INTO rnd.ticket (oncall) VALUES (" + s + ") WHERE tickitid = "+ ticketid );
   }
   
   public void changedate_end(int ticketid)
   {
	   Query("INSERT INTO rnd.ticket (date_end) VALUES (" + date() + ") WHERE tickitid = "+ ticketid );
   }
   
   public void changeStatus(int ticketid, int s)
   {
	   Query("INSERT INTO rnd.ticket (status) VALUES (" + s + ") WHERE tickitid = "+ ticketid );
   }
   
   public String date(){
	   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       Date date = new Date();
       return dateFormat.format(date);
   }
   
}
